package com.game.springbootstart.service.impl;

import com.game.springbootstart.entity.Admin;
import com.game.springbootstart.entity.Favorites;
import com.game.springbootstart.entity.Games;
import com.game.springbootstart.mapper.AdminMapper;
import com.game.springbootstart.mapper.FavoritesMapper;
import com.game.springbootstart.mapper.GamesMapper;
import com.game.springbootstart.service.IFavoritesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 喜欢表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-12
 */
@Service
public class FavoritesServiceImpl extends ServiceImpl<FavoritesMapper, Favorites> implements IFavoritesService {

    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private FavoritesMapper favoritesMapper;
    @Autowired
    private GamesMapper gamesMapper;

    @Override
    public boolean addFavorite(Long userId, Long gameId) {
        Admin admin = adminMapper.listById(userId);
        Games games = gamesMapper.selectById(gameId);
        Boolean flag = false;
        if (admin != null && games != null) {
            LocalDateTime now = LocalDateTime.now();
            flag = favoritesMapper.save(userId,gameId,now);
        }
        return flag;
    }

    @Override
    public List<Games> listBy(Long userId) {
        return favoritesMapper.listBy(userId);
    }

    @Override
    public Boolean delete(Long userId, Long gameId) {
        return favoritesMapper.deleteBy(userId,gameId);
    }

    @Override
    public List<Long> selectFavorites(Long userId) {
        return favoritesMapper.selectFavorites(userId);
    }
}
